package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.domain.SetmealDish;
import com.itheima.reggie.mapper.SetmealDishMapper;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class SetmealController {


    @Autowired
    private SetmealService setmealService;
    @Autowired
    private SetmealDishMapper setmealDishMapper;

    //分页条件管理
    @GetMapping("/setmeal/page")
    public ResultInfo findByPage(@RequestParam("page") Integer pageNum,
                                 @RequestParam("pageSize") Integer pageSize,
                                 String name) {
        //调用service
        Page<Setmeal> page = setmealService.findbyPage(pageNum, pageSize, name);
        //返回结果
        return ResultInfo.success(page);

    }

    //回显数据
    @GetMapping("/dish/list")
    public ResultInfo findByType(Long categoryId, String name) {
        //调用service
        List<Dish> dishList = setmealService.findbyType(categoryId, name);
        //返回结果
        return ResultInfo.success(dishList);
    }


    //新增套餐
    @PostMapping("/setmeal")
    public ResultInfo save(@RequestBody Setmeal setmeal) {//接受参数
        //调用service
        setmealService.save(setmeal);
        //返回数据
        return ResultInfo.success();
    }

    //套餐回显
    @GetMapping("/setmeal/{id}")
    public ResultInfo findById(@PathVariable("id") Long id) {
        //调用service
        Setmeal setmeal = setmealService.findById(id);
        //放回结果
        return ResultInfo.success(setmeal);
    }

    //修改套餐
    @PutMapping("/setmeal")
    public ResultInfo update(@RequestBody Setmeal setmeal) {
        //调用service
        setmealService.update(setmeal);
        //返回结果
        return ResultInfo.success();
    }

    //启停售卖
    @PostMapping("/setmeal/status/{status}")
    public ResultInfo updateStatus(@PathVariable("status") Integer status, @RequestParam List<Long> ids) {//list集合接受配合@RequestParam
        //调用service
        setmealService.updateStatus(status, ids);
        //返回结果
        return ResultInfo.success();

    }
    //套餐删除
    @DeleteMapping("/setmeal")
    public ResultInfo delete(@RequestParam List<Long> ids) {//接受参数
        //调用service
        setmealService.delete(ids);
        //返回结果
        return ResultInfo.success();
    }
}
